﻿using System;

namespace VisualWip.Core
{
    public class ErrorWorkItem : WorkItem
    {
        public ErrorWorkItem()
        {
            TypeName = "ErrorWorkItem";
        }

        public ErrorWorkItem(string title, string description) : this()
        {
            Title = title;
            Fields.Add("Description", description);
        }

        public ErrorWorkItem(Exception exception)
            : this()
        {
            PopulateWithException(exception);
        }

        protected virtual void PopulateWithException(Exception exception)
        {
            Title = exception.GetType().Name;
            Fields.Add("Exception", exception);
            Fields.Add("Description", exception.Message);
            Fields.Add("Message", exception.Message);
            Fields.Add("Source", exception.Source);
            Fields.Add("StackTrace", exception.StackTrace);
        }
    }
}